package com.cn.lyl.servlet.service;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.Page;
import com.cn.lyl.model.ServiceModel;
import com.cn.lyl.service.ServiceService;
import com.cn.lyl.service.impl.ServiceServiceImpl;
import com.cn.lyl.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/service/list")
public class FindAllServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String serviceName = req.getParameter("serviceName");
        String type = req.getParameter("type");
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        ServiceModel serviceModel = new ServiceModel();
        serviceModel.setServiceName(serviceName);
        serviceModel.setStart(start);
        serviceModel.setEnd(end);
        serviceModel.setDependenceObj(type);
        Page page=new Page();
        page.setPageCurr(Tool.curr(req.getParameter("page")));
        page.setPageSize(Tool.size(req.getParameter("limit")));
        serviceModel.setPage(page);
        ServiceService serviceService = new ServiceServiceImpl();
        List<ServiceModel> allService = serviceService.findAllService(serviceModel);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","");
        jsonObject.put("count",serviceService.getCount(serviceModel));
        jsonObject.put("data",allService);
        resp.getWriter().print(jsonObject);

    }
}
